package com.tentact.dao;

import com.tentact.vo.Department;


import java.sql.SQLException;
import java.util.List;

public class DeptDao {

    //查询所有部门
    public List<Department> selectAllDept(){
        String sql ="select departmentid,departmentname,remark from department";
        RowMapper<Department> rm =(rs)->{
            Department department =new Department();
            try {
                department.setDepartmentid(rs.getInt("departmentid"));
                department.setDepartmentname(rs.getString("departmentname"));
                department.setRemark(rs.getString("remark"));
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return department;
        };
        return Dbutil.executeQuery(sql, null, rm);
    }

    //添加部门
    public int insertDept(String Deptname) {
        String sql="insert into department(departmentname) values(?);";
        Object[] params = {Deptname};
        return Dbutil.executeUpdate(sql, params);
    }

    //修改部门
        public int updateDept(Department department) {
        String sql="update department set departmentname = ? where DepartmentId = ?";
        Object[] params = {department.getDepartmentname(),department.getDepartmentid()};
        return Dbutil.executeUpdate(sql, params);
    }

    //删除
        public int deleteByDept(int DepartmentId){
        String sql ="DELETE FROM department WHERE DepartmentId =?";
        Object[] params = {DepartmentId};
        return Dbutil.executeUpdate(sql, params);
    }


}
